﻿using System;
using System.Collections.Generic;

namespace TraceView.Shared.Handlers.DefaultHandler
{
    public class DefaultTraceHandler : ITraceHandler
    {
        #region ITraceHandler Members

        public TraceObject Serialize(object instance)
        {
            var traceObject = new TraceObject(typeof (string).ToString());
            if (instance is IDictionary<string, object>)
            {
                var dictionary = (Dictionary<string, object>) instance;
                object message;
                if (dictionary.TryGetValue("Message", out message))
                    traceObject.DataItems.Add(new DataItem("Message", message.ToString()));
            }
            return traceObject;
        }

        public IBaseHandlerView GetView(TraceData traceData)
        {
#if IsListener
            throw new NotImplementedException();
#else

            string message = traceData.TraceObject.DataItems[0].Value;
            return new DefaultHandlerView(message);
#endif
        }

        #endregion
    }
}